﻿using System;
using System.Collections;
using LuaFramework;
using LuaInterface;
using UnityEngine;

public class ProcInit : Proc
{
    public override void onBegin(object[] additionalParams)
    {
        AppFacade.networkManager.TcpClose();
        AppFacade.networkManager.KcpClose();
        AppFacade.gameManager.StartCoroutine(DoBegin());
    }

    IEnumerator DoBegin()
    {
        yield return null;
        AppFacade.Instance.GetManager<ResourceManager>(ManagerName.Resource).Initialize(LoadManager.DATA);
        AppFacade.Instance.GetManager<LuaManager>(ManagerName.Lua).InitStart();
#if TEST 
        AppFacade.Instance.GetManager<LuaManager>(ManagerName.Lua).lua["IsTest"] = true;
#endif
        AppFacade.Instance.GetManager<LuaManager>(ManagerName.Lua).lua.DoFile("Main.lua");
        LuaFunction main = AppFacade.Instance.GetManager<LuaManager>(ManagerName.Lua).lua["Main"] as LuaFunction;
        main.Call();
    }

    public override void process()
    {
        
    }

    public override void fixedUpdate()
    {
        
    }

    public override void onEnd()
    {
        AppFacade.eventManager.DispatchEvent("ui_lua_start");
    }
}
